﻿@model NewCity.Models.StorySeries
@{
    ViewData["Title"] = "Creator";
    List<StorySeries> storySeries = ViewBag.storySeries as List<StorySeries>;
}
<h2>详情</h2>
<hr />
<div class="container">
    <div class="row">
        <button class="btn btn-primary" data-toggle="modal" data-target="#Addseries">新增</button>
    </div>
    <div class="row">
        @if (storySeries.Count != 0)
        {
            @foreach (var item in storySeries)
            {

        <div class="unitcell col-md-4">
            <div>
                <h1>@item.SeriesName</h1>
            </div>
            <div>
                @item.Text
            </div>
            @if (item.Status != NewCity.Enum.enumStoryStatus.进行中 && item.Status != NewCity.Enum.enumStoryStatus.审批中)
            {
                <a class="btn btn-primary" asp-controller="CreateStory" asp-action="FlowChart" asp-route-id="@item.ID">编辑</a>

            }
            @if (item.Status == NewCity.Enum.enumStoryStatus.测试)
            {
                <a class="btn btn-primary" onclick="Active('@item.ID')">启用</a>
            }
            else if(item.Status == NewCity.Enum.enumStoryStatus.审批中)
            {
                <a class="btn btn-warning">审批中</a>
            }
            else
            {
            <a class="btn btn-primary" onclick="AntiActive('@item.ID')">停用</a>
            }
            <a class="btn btn-primary" href="/Main/Main?SeriesID=@item.ID">测试</a>
            <a class="btn btn-primary" onclick="DeleteConfirm('@item.ID')">删除</a>
            <p></p>
            <div style="background-color:lemonchiffon">
                @item.ReviewContent
            </div>
        </div>
            }
        }
    </div>
</div>

<div class="modal fade" id="Addseries" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title" id="myModalLabel"></h4>
            </div>
            <div class="modal-body">
                <form asp-action="Index">
                    <div class="form-group">
                        <label asp-for="SeriesName" class="control-label">故事名称</label>
                        <input asp-for="SeriesName" class="form-control" />
                        <span asp-validation-for="SeriesName" class="text-danger"></span>
                    </div>
                    <div class="form-group">
                        <label asp-for="Text" class="control-label">简介</label>
                        <input asp-for="Text" class="form-control" />
                        <span asp-validation-for="SeriesName" class="text-danger"></span>
                    </div>
                    <button type="submit" onclick="reload()">确定</button>
                    <button type="reset">取消</button>
                </form>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="Integrity" >
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title" id="myModalLabel">完整性检查</h4>
            </div>
            <div class="modal-body" id="IntegrityList">
                
            </div>
        </div>
    </div>
</div>

<script>
    function reload() {
        window.location.reload();
    }

    function DeleteConfirm(id) {
        let msg = "您真的确定要删除吗？\n\n请确认！";
        if (confirm(msg)) {
            $.post("/Creator/Delete", { id: id }, function (data) {
                window.location.reload();
            })
        }
    }
    function Active(id) {
        $.post("/Creator/Active", { id: id }, function (data) {
            if (data == true) {
                window.location.reload();
            }
            else if (data == false) {
                alert("处理中出现问题！")
            }
            else {
                $('#IntegrityList').append("<p><strong>以下故事卡片未通过完整性检验：</strong></p>" + data + "<p><b>请完善该卡片的后续。</b></p>")
                $('#Integrity').modal('show')
            }
        })
    }
    function AntiActive(id) {
        $.post("/Creator/AntiActive", { id: id }, function (data) {
            window.location.reload();
        })
    }

</script>
